<?php

require_once 'docgeral.modelo.class.php';

class DocGeralControl {

    function DocGeralControl() {

        if (isset($_POST['action']) && $_POST['action'] == "docgeral_insert") {

            if ($_POST['type'] == NULL || $_POST['number'] == NULL || $_POST['name'] == NULL || $_POST['flag'] == NULL) {
                echo "Preencha todos os campos";

                return false;
            }
			

        $docgeralModelo = new DocGeralModelo();
        $docgeralModelo->setType($_POST['type']);
        $docgeralModelo->setNumber($_POST['number']);
		$docgeralModelo->setName($_POST['name']);	
       	$docgeralModelo->setName($_POST['flag']);

	     $docgeralModelo->insert();

            header("Location: ../index.php");
        }
		
        if (isset($_POST['action']) && $_POST['action'] == "docgeral_update") {

            if ($_POST['type'] == NULL || $_POST['number'] == NULL || $_POST['name'] == NULL || $_POST['flag'] == NULL) {
                echo "Preencha todos os campos";

                return false;
            }
			
        $docgeralModelo = new DocGeralModelo();
        $docgeralModelo->setType($_POST['type']);
        $docgeralModelo->setNumber($_POST['number']);
		$docgeralModelo->setName($_POST['name']);
		$docgeralModelo->setName($_POST['flag']);

		$docgeralModelo->updateType();
		$docgeralModelo->updateNumer();
		$docgeralModelo->updateName();
		$docgeralModelo->updateFlag();

			
            header("Location: ../index.php");
        }

        if (isset($_GET['action']) && $_GET['action'] == "docgeral_delete") {

            $docgeralModelo = new DocGeralModelo();
            $docgeralModelo->setId($_GET['id']);

            $docgeralModelo->delete();

            header("Location: ../index.php");
        }
		
	}
	
    function selectDocGeral($id) {
        $docgeralModelo = new DocGeralModelo();
        $array = $docgeralModelo->select("WHERE id = ".$id);
        return $array;
    }
	

    function selectAll() {
        $docgeralModelo = new DocGeralModelo();
        $array = $docgeralModelo->select("");
        return $array;
    }
	
}

?>

